// 源插件
import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import router from 'umi/router';

// 视图插件
import {
  Spin,
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Steps,
  Radio,
  Upload,
} from 'antd';

// 外部组件
import StandardTable from '@/components/StandardTable';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

// css OR less预编译器

// 图片

const FormItem = Form.Item;
const { Option } = Select;

/**
 *  Created by xjc on 2019/8/15
 *  Describe:数据连接
 */

@connect(({ stockHistory }) => ({
  stockHistory,
}))
@Form.create()
class AddStockHistory extends PureComponent {
  componentWillMount() {}

  /**
   *  Created by xjc on 2019/8/15
   *  Describe:当前状态
   */

  state = {
    confirmLoading: false,
  };

  onChange = e => {};

  okHandle() {
    const that = this;
    that.setState({
      confirmLoading: true,
    });
    return new Promise((resolve, reject) => {
      setTimeout(resolve, 800);
    })
      .then(() => {
        that.setState({
          confirmLoading: false,
        });
        that.props.form.validateFields((err, values) => {
          if (!err) {
            const { dispatch } = that.props;
            dispatch({
              type: 'stockHistory/AddSummary',
              payload: {
                stock: values.stock,
                operateType: values.operateType,
                operateNum: values.operateNum,
                operatePrice: values.operatePrice,
                bank: values.bank,
                aqDqMark: values.aqDqMark,
                reason: values.reason,
                tradeDate: values.tradeDate.format('YYYY-MM-DD'),
              },
              callback: res => {
                that.props.closeVisbile();
              },
            });
          }
        });
      })
      .catch(() => console.log('Oops errors!'));
  }

  cancelHandle() {
    this.props.closeVisbile();
  }

  render() {
    const { confirmLoading } = this.state;
    const { visible, form } = this.props;
    const { getFieldDecorator } = form;

    return (
      <Modal
        destroyOnClose
        title="修改"
        visible={visible}
        width="60%"
        centered
        onOk={this.okHandle.bind(this)}
        confirmLoading={confirmLoading}
        onCancel={this.cancelHandle.bind(this)}
      >
        <Form onSubmit={this.handleSearch} style={{ overflowY: 'scroll' }}>
          <Row>
            <FormItem label="股票" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('stock', { initialValue: '' })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            <FormItem label="类型" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('operateType', { initialValue: '' })(
                <Select style={{ width: '85%' }}>
                  <Option value={0}>卖</Option>
                  <Option value={1}>买</Option>
                </Select>
              )}
            </FormItem>
            <FormItem label="银行" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('bank', { initialValue: '' })(
                <Select style={{ width: '85%' }}>
                  <Option value={1}>瑞银</Option>
                  <Option value={2}>花旗</Option>
                </Select>
              )}
            </FormItem>
            <FormItem label="标识" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('aqDqMark', { initialValue: '' })(
                <Select style={{ width: '85%' }}>
                  <Option value={0}>股票操作</Option>
                  <Option value={1}>AQDQ操作</Option>
                  <Option value={2}>行权</Option>
                  <Option value={3}>到期行权</Option>
                </Select>
              )}
            </FormItem>
            <FormItem label="数量" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('operateNum', { initialValue: '' })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            <FormItem label="价格" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('operatePrice', { initialValue: '' })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            <FormItem label="交易时间" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {form.getFieldDecorator('tradeDate', {
                initialValue: '',
                rules: [{ type: 'object' }],
              })(
                <DatePicker
                  style={{ width: '85%' }}
                  // showTime
                  format="YYYY-MM-DD"
                  placeholder="交易时间"
                />
              )}
            </FormItem>
            <FormItem label="理由" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('reason', { initialValue: '' })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
          </Row>
        </Form>
      </Modal>
    );
  }

  componentDidMount() {}

  componentWillUnmount() {}
}

export default AddStockHistory;
